package com.blockmeta.bbs.businesslibrary.net.rxjava;

import android.content.Context;

import com.blockmeta.bbs.baselibrary.utils.ToastUtil;
import com.blockmeta.bbs.baselibrary.utils.loading.ProgressBarUtil;

import io.reactivex.observers.DisposableObserver;

/**
 * Created by author
 * Date 2019/8/7
 * 处理GraphQL的dispose关系
 */
public abstract class BaseDisposableObserver<T>  extends DisposableObserver<T> {

    private boolean showOtherException;
    private Context mContext;

    public BaseDisposableObserver(Context context) {
        mContext = context;
    }

    public BaseDisposableObserver(Context context, boolean showOtherException) {
        mContext = context;
        this.showOtherException = showOtherException;
    }

    @Override
    public void onComplete() {
        ProgressBarUtil.dismissProgress(mContext);
    }

    @Override
    public void onError(Throwable t) {
        ProgressBarUtil.dismissProgress(mContext);
        if (t instanceof CustomException) {
            ToastUtil.show(t.getMessage());
        } else if (showOtherException) {
            ToastUtil.show(t.getMessage());
        }
    }
}
